----------------------------------------------------------------------------------------------------------------------------------------------------
--[[

    转换成另外一个帽子的执行逻辑

]]--
----------------------------------------------------------------------------------------------------------------------------------------------------
--- sky 2 ground
    local function sky_2_ground_trans_logic(inst,_table)
        local full_value = inst.components.hutao_com_cosmic_hat_sys_for_item:GetCurrent()
        local is_equipping = inst.components.equippable:IsEquipped()
        local owner = inst.components.inventoryitem.owner
        local linked_player = inst.components.hutao_com_cosmic_hat_sys_for_item:GetLinkedPlayer()
        local x,y,z = inst.Transform:GetWorldPosition()
        local item_records = {}
        for k,item_in_slot in pairs(inst.components.container.slots) do
            if item_in_slot and item_in_slot:IsValid() then
                -- table.insert(item_records,item_in_slot:GetSaveRecord())
                item_records[#item_records+1] = item_in_slot:GetSaveRecord()
            end
        end
        inst:Remove()
        local new_hat = SpawnPrefab("hutao_equipment_cosmic_hat_ground")
        -- new_hat.components.hutao_com_cosmic_hat_sys_for_item:LinkPlayer(linked_player)
        linked_player.components.hutao_com_cosmic_hat_sys_for_player:SetHat(new_hat)
        new_hat.components.hutao_com_cosmic_hat_sys_for_item:SetMax(full_value)
        new_hat.components.hutao_com_cosmic_hat_sys_for_item:SetCurrent(full_value)
        if is_equipping and owner then
            owner.components.inventory:Equip(new_hat)
            for i, temp_record in ipairs(item_records) do
                local temp_item = SpawnSaveRecord(temp_record)
                owner.components.inventory:GiveItem(temp_item)
            end
        else
            for i, temp_record in ipairs(item_records) do
                local temp_item = SpawnSaveRecord(temp_record)
                temp_item.Transform:SetPosition(x,3,z)
                temp_item.components.inventoryitem:DoDropPhysics(x,y,z,1,1)
            end
            new_hat.components.inventoryitem:DoDropPhysics(x,y,z)
        end
    end
    local function sky_fn(inst)
        if not TheWorld.ismastersim then
            return
        end
        inst:ListenForEvent("onbadluckfull",sky_2_ground_trans_logic)
    end
----------------------------------------------------------------------------------------------------------------------------------------------------
--- ground 2 sky
    local function ground_2_sky_trans_logic(inst,_table)
        local is_equipping = inst.components.equippable:IsEquipped()
        local owner = inst.components.inventoryitem.owner
        local x,y,z = inst.Transform:GetWorldPosition()
        local linked_player = inst.components.hutao_com_cosmic_hat_sys_for_item:GetLinkedPlayer()
        inst:Remove()
        local new_hat = SpawnPrefab("hutao_equipment_cosmic_hat_sky")
        -- new_hat.components.hutao_com_cosmic_hat_sys_for_item:LinkPlayer(linked_player)
        linked_player.components.hutao_com_cosmic_hat_sys_for_player:SetHat(new_hat)
        if is_equipping and owner then
            owner.components.inventory:Equip(new_hat)
        elseif owner and owner.components.inventory then
            owner.components.inventory:GiveItem(new_hat)
        else
            new_hat.components.inventoryitem:DoDropPhysics(x,y,z)
        end
    end
    local function ground_fn(inst)
        if not TheWorld.ismastersim then
            return
        end
        inst:ListenForEvent("onbadluckempty",ground_2_sky_trans_logic)
    end
----------------------------------------------------------------------------------------------------------------------------------------------------
return {
    sky = sky_fn,
    ground = ground_fn,
}
